* Set directories
cd /Users/byrned/Dropbox/Research/InformedSources/Replication/Analysis/
local datdir /Users/byrned/Dropbox/Research/InformedSources/Replication/Build/Output/


*------------------ Example Cycles Before Coles Exits Platform ----------------*

* Load data
use `datdir'is_mel_p_2005_2019, clear

* Compute mean price by market, brand, date
sort bid t
collapse (mean) p c (sd) p_sd=p, by(bid t)
save Temp/temp, replace

* Before period
keep if t>=td(15may2015) & t<td(1aug2015)

* Dates for xlabels
local x1=td(15may2015)
local x2=td(1jun2015)
local x3=td(15jun2015)
local x4=td(1jul2015)
local x5=td(15jul2015)
local x6=td(1aug2015)
local panel1=td(17may2015)+0.5
local panel2=td(4jun2015)

* Cycles Before Coles Exits Platforms
twoway 	(line p t if bid==1, lwidth(thin)   connect(stairstep) lcolor(gs0*0.85)  lpattern(dash)) ///
		(line p t if bid==2, lwidth(thin)   connect(stairstep) lcolor(gs0*0.7)   lpattern(shortdash) ) ///
		(line p t if bid==3, lwidth(medthick) connect(stairstep) lcolor(gs0)  lpattern(solid) ) ///
		(line p t if bid==4, lwidth(thin)   connect(stairstep) lcolor(gs0*0.55) lpattern(dash_dot)) ///
		(line p t if bid==5, lwidth(thin)   connect(stairstep) lcolor(gs0*0.4) lpattern(longdash)) ///
		(line c t if bid==1, lwidth(medium) connect(stairstep) lcolor(gs0) lpattern(shortdash)  ///		
		ytitle("Mean Station-Level Retail Price (cpl)", height(6)) ylabel(120(10)160, labsize(*0.8) grid gmin gmax) ///
		xtitle("Date", height(6)) ///
		xlabel(`x1' `" "May 15"   "2015" "' `x2' `" "Jun 1"   "2015" "'  `x3' `" "Jun 15"   "2015" "'  `x4' `" "Jul 1"   "2015" "'  ///
			   `x5' `" "Jul 15"   "2015" "'  `x6' `" "Aug 1"   "2015" "' , labsize(*0.7)) ///
		plotregion(margin(zero) style(none)) ///
		text(122 `panel1' "{bf:A}", justification(right) size(*2)) ///
		text(122 `panel2' "        Symmetric Information Sharing", justification(right) size(*1.25)) ///
		legend(ring(0) size(*0.75) position(11) symx(*0.5) symy(*0.5) region(lwidth(*0.05)) rows(1) ///
		label(1 "BP") label(2 "Caltex") label(3 "Coles") label(4 "Woolworths") label(5 "7-Eleven") label(6 "Wholesale" "TGP")))
graph export Output/fig4a_zoom_before.pdf, as(pdf) replace

*------------------- Example Cycles After Coles Exits Platform ----------------*

use Temp/temp, clear
keep if t>=td(15may2017) & t<td(1aug2017)

* Dates for xlabels
local x1=td(15may2017)
local x2=td(1jun2017)
local x3=td(15jun2017)
local x4=td(1jul2017)
local x5=td(15jul2017)
local x6=td(1aug2017)
local panel1=td(17may2017)+0.5
local panel2=td(5jun2017)

* Cycles After Coles Exits Platform
twoway 	(line p t if bid==1, lwidth(thin)   connect(stairstep) lcolor(gs0*0.85)  lpattern(dash)) ///
		(line p t if bid==2, lwidth(thin)   connect(stairstep) lcolor(gs0*0.7)   lpattern(shortdash) ) ///
		(line p t if bid==3, lwidth(medthick) connect(stairstep) lcolor(gs0)  lpattern(solid) ) ///
		(line p t if bid==4, lwidth(thin)   connect(stairstep) lcolor(gs0*0.55) lpattern(dash_dot)) ///
		(line p t if bid==5, lwidth(thin)   connect(stairstep) lcolor(gs0*0.4) lpattern(longdash)) ///
		(line c t if bid==1, lwidth(medthick) connect(stairstep) lcolor(gs0) lpattern(short_dash)  ///		
		ytitle("Mean Station-Level Retail Price (cpl)", height(5)) ylabel(100(10)140, labsize(*0.8) grid) ///
		xtitle("Date", height(6)) ///
		text(102 `panel1' "{bf:B}", justification(right) size(*2)) ///
		text(102 `panel2' "        Asymmetric Information Sharing", justification(right) size(*1.25)) ///
		xlabel(`x1' `" "May 15"   "2017" "' `x2' `" "Jun 1"   "2017" "'  `x3' `" "Jun 15"   "2017" "'  `x4' `" "Jul 1"   "2017" "'  ///
			   `x5' `" "Jul 15"   "2017" "'  `x6' `" "Aug 1"   "2017" "' , labsize(*0.7)) ///
		plotregion(margin(zero) style(none)) legend(off))
graph export Output/fig4b_zoom_after.pdf, as(pdf) replace		

